<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		#box{
			width: 200px;
			height: 200px;
			background: red url() 0 0 no-repeat;
		}
	</style>

	<script type="text/javascript">
		window.onload = function(){


			btn = document.getElementById('btn');

			box = document.getElementById('box');


			btn.onclick = function () {
				if(btn.value=='开始'){
					btn.value='停止';
					time = setInterval(run, 10);
				}else{
					btn.value='开始';
					clearInterval(time);
				}
			}

			x = 1;

			function run () {
				
				height = window.getComputedStyle ? window.getComputedStyle(box,null).height : box.currentStyle.height;

				height = parseInt(height)

				if(height>400){
					x=0;
				}else if(height<200){
					x=1;
				}

				if(x==1){
					height = height+5;
				}else{
					height = height-5;
				}

				box.style.height=height+"px";
				box.style.width=height+"px";




			}



		}
	</script>
</head>
<body>
	<input type="button" value="开始" id="btn">
	<div id="box"></div>
</body>
</html>